/* vue-i18n 插件使用方法：
安装 npm i vue-i18n
1、main.ts直接use：
  app.use(I18N.use)
2、页面使用：
  import {useI18n} from 'vue-i18n'
  const { t } = useI18n()
  console.log(t('input.boyName'))
3、切换语言：
  I18N.setLanguage('zh')
* */

import {createI18n} from "vue-i18n";
import pt from './lang/pt-BR'
import en from './lang/en-US'
import zh from './lang/zh-CN'
type SupportedLocales = 'pt' | 'en' | 'zh'

export class I18N {

  static use = createI18n({
    legacy: false,
    locale: localStorage.getItem('locale') || 'pt',
    fallbackLocale: 'en',
    messages: {
      'pt': pt,
      'en': en,
      'zh': zh,
    }
  })

  //返回en或zh等messages内的key
  static getCurrLanguage(): string {
    return I18N.use.global.locale.value;
  }

  //传入en或zh等messages内的key
  static setLanguage(locale: string) {
    I18N.use.global.locale.value = locale as SupportedLocales;
    localStorage.setItem('locale', locale);
  }
}